package com.sky.controller.user;


import com.sky.pojo.Merchant;
import com.sky.result.Result;
import com.sky.service.user.MerchantService;
import com.sky.vo.ShopVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@ApiOperation("用户查询店铺的营业状态")
@RequestMapping("/user/shop")
public class UserShopController {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private MerchantService merchantService;
    public static final String KEY="SHOP_STATUS";
    @GetMapping("/status")
    public Result<Integer> getStatus(){
        Integer STATUS = (Integer) redisTemplate.opsForValue().get(KEY);
        log.info("营业状态：{}",STATUS==1?"营业中":"打样中");
        return Result.success(STATUS);
    }

    @GetMapping("/getMerchantInfo")
    @ApiOperation("获取商家信息")
    public Result<ShopVO>   getMerchantInfo(){
        //  获取唯一商家对象信息
        Merchant merchant = merchantService.getShopById(1L);
        String  shopName = merchant.getShopName();
        String  shopAddress = merchant.getShopAddress();
        String  shopTelephone = merchant.getShopTelephone();
        //包装shopVo对象
        ShopVO build = ShopVO.builder()
                .phone(shopTelephone)
                .shopName(shopName)
                .shopAddress(shopAddress)
                .build();
        return  Result.success(build);
    }
}
